// src/hooks/useLogin.js
import axios from "axios"
import { useEffect, useState } from "react"

function useLogin () {
    // [是否登录， 是否正在发送请求]
    const [status, setStatus] = useState([false, true])
    useEffect(() => {
        const token = localStorage.getItem('token')
        if (token) {
            try {
                axios.get('/user', {
                    headers: {
                        Authorization: `Token ${token}`
                    }
                })
                setStatus([true, false])
            } catch (error) {
                setStatus([false, false])
            }
        } else {
            setStatus([false, false])
        }
    }, [])
    return status
}

export default useLogin